/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.uhk.ppro.response.web;

import cz.uhk.ppro.response.service.DatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Martin Zmítko <martin.zmitko@gmail.com>
 */

@Controller
@SessionAttributes("filtrForm")
public class StudentsController {

    @Autowired
    private DatabaseService databaseSession;

    @RequestMapping(value="/smazStudenta", method=RequestMethod.POST)
    protected String smaz(@RequestParam(value = "id") Integer id)
    {
        databaseSession.odstranStudenta(id);

        return "redirect:/pupils.do";
    }

    @RequestMapping("/pupils.do")
    public ModelAndView zobrazit()
    {
        ModelAndView model = new ModelAndView("pupils");

        model.addObject("studenti", databaseSession.getStudenti());

        return model;
    }

    @RequestMapping("/pupilsprint.do")
    public ModelAndView zobrazitTisk()
    {
        ModelAndView model = new ModelAndView("pupilsPrint");

        model.addObject("studenti", databaseSession.getStudentiByLastName());

        return model;
    }




}
